package org.idea.spring.bean.source;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.annotation.PostConstruct;

/**
 * @Author linhao
 * @Date created in 11:47 上午 2021/5/3
 */
public class ResolvableDependencySourceDemo  {

    @Autowired
    private String value;

    @PostConstruct
    public void init()  {
        System.out.println(this.value);
    }

    public static void main(String[] args) {
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
        annotationConfigApplicationContext.register(ResolvableDependencySourceDemo.class);
        annotationConfigApplicationContext.addBeanFactoryPostProcessor(beanFactory -> {
            beanFactory.registerResolvableDependency(String.class,"hello world");
        });
        annotationConfigApplicationContext.refresh();
        String value = annotationConfigApplicationContext.getBean(String.class);
        System.out.println(value);
        annotationConfigApplicationContext.close();
    }


}
